<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:doc="livcos.org/ns/doc"
  xmlns:bm="livcos.org/ns/bm"
  xmlns="http://www.w3.org/1999/XSL/Format"
  exclude-result-prefixes="doc bm">
  
  <xsl:decimal-format grouping-separator="'"/>
  <xsl:variable name="currency-picture">#'###.00</xsl:variable>

  <xsl:template match="bm:forecast">
    <table-row>
      <table-cell padding="1pt" border-top-style="solid" margin-left="0.2cm"
        border-width="thin">
        <block>
          <xsl:value-of select="@year" />
        </block>
      </table-cell>
      <table-cell padding="1pt" border-left-style="solid" border-top-style="solid"
        border-width="thin" text-align="right" margin-left="0cm" margin-right="0.1cm">
        <block>
          <xsl:value-of select="format-number(sum(bm:revenue/@amount), $currency-picture)" />
        </block>
      </table-cell>
      <table-cell padding="1pt" border-left-style="solid" border-top-style="solid"
        border-width="thin" text-align="right" margin-left="0cm" margin-right="0.1cm">
        <block>
          <xsl:value-of select="format-number(sum(bm:expense/@amount), $currency-picture)" />
        </block>
      </table-cell>
      <table-cell padding="1pt" border-left-style="solid" border-top-style="solid"
        border-width="thin" margin-left="0.1cm">
        <block>
          <xsl:apply-templates select="bm:body-count" />
        </block>
      </table-cell>
    </table-row>
  </xsl:template>
  
  <xsl:template match="bm:body-count">
    <xsl:if test="position() > 1">, </xsl:if>
    <xsl:value-of select="@position"/>: <xsl:value-of select="@count"/>
  </xsl:template>
  
  <xsl:template match="bm:forecast[bm:forecast]">
    <table table-layout="fixed" width="90%" margin-left="0.6cm" margin-top="12pt"
      font-size="8pt" >
      <table-column column-width="8%" />
      <table-column column-width="17%" />
      <table-column column-width="17%" />
      <table-column column-width="58%" />
      <table-header>
        <table-row>
          <table-cell padding="1pt" margin-left="0.1cm"
                      background-color="#EEEEEE">
            <block>Year</block>
          </table-cell>
          <table-cell padding="1pt" border-left-style="solid" margin-left="0.1cm"
                      border-width="thin" background-color="#EEEEEE">
            <block>Revenue</block>
          </table-cell>
          <table-cell padding="1pt" border-left-style="solid" margin-left="0.1cm"
                      border-width="thin" background-color="#EEEEEE">
            <block>Expenses</block>
          </table-cell>
          <table-cell padding="1pt" border-left-style="solid" margin-left="0.1cm"
                      border-width="thin" background-color="#EEEEEE">
            <block>Body Count</block>
          </table-cell>
        </table-row>
      </table-header>
      <table-body>
        <xsl:apply-templates select="bm:forecast" />
      </table-body>
    </table>
  </xsl:template>
  
</xsl:stylesheet>
